package Try;

import java.util.ArrayList;
import java.util.List;

public class Main13 {
    public static void main(String[] args) {
        System.out.println(solution(4));

    }

    public static int solution(int n){
        List<Integer> list = new ArrayList<>(n);
        for (int i=0;i<n;i++){
            list.add(i+1);
        }

        int number = 1;
        int index = 0;
        while (list.size()!=1){
            if (number!=3){
                number++;
                index = (index+1)%list.size();
            }else {
                list.remove(index);
                index = index%list.size();
                number = 1;
            }
        }

        return list.get(0);
    }
}
